/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.ms1_intensitiesretrieval;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import org.apache.log4j.Level;

/**
 *
 * @author Jonas
 */
public class OutputWriter {

    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(OutputWriter.class);
    private static final String COLUMN_SEPARATOR = "\t";

    public void writeSpectrumVariablesToFile(List<MSLimsHits> identifications, File output, int projectID) {

        LOGGER.setLevel(Level.ALL);

        PrintWriter printWriter = null;

        try {
            FileWriter fileWriter = new FileWriter(output);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            printWriter = new PrintWriter(bufferedWriter);

            // Print column headers
            printWriter.println("projectID" + COLUMN_SEPARATOR + "precursorMZ" + COLUMN_SEPARATOR + "rtSec" + COLUMN_SEPARATOR + "totalMS2Int" + COLUMN_SEPARATOR + "measureStartPoint"
                    + COLUMN_SEPARATOR + "measureEndPoint" + COLUMN_SEPARATOR + "openMSInt" + COLUMN_SEPARATOR + "highestPeakIntensity" + COLUMN_SEPARATOR + "sumOfPeaks");

            for (MSLimsHits identification : identifications) {
                printWriter.print(projectID);
                printWriter.println("\t" + identification.toString());
            }
            LOGGER.info(output + " saved!\n");
            printWriter.close();
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
